<?php
session_start();
require_once("database.php");
$conn=mysql_link();


$us=$_SESSION['email'];
$cha="SELECT borrowrecords.*,users.* FROM borrowrecords INNER JOIN users on borrowrecords.UserID = users.UserID where Email='$us'";
$sql2= mysqli_query($conn,$cha);
$res2= mysqli_fetch_assoc($sql2);
$username = $res2["Name"];
//echo $username;
//echo $us;
//$sql="SELECT ReturnDate  FROM borrowrecords where ReturnDate and UserID='$username' and re=1";
//$sql1= mysqli_query($conn,$sql);
//$res= mysqli_fetch_assoc($sql1);
//$reture=
$data=date("Y-m-d H:i:s");
//echo $data;
$sql5= "SELECT borrowrecords.*,users.* FROM borrowrecords INNER JOIN users on borrowrecords.UserID = users.UserID  WHERE Name = '$username' AND re = 1 AND ReturnDate < '$data'";;
$sql5= mysqli_query($conn,$sql5);
$res5=mysqli_fetch_all($sql5,MYSQLI_ASSOC);
//print_r($res5);
$count1 = mysqli_num_rows($sql5);
$sql3="SELECT borrowrecords.*,users.* FROM borrowrecords INNER JOIN users on borrowrecords.UserID = users.UserID  where Name='$username' and re=1 AND ReturnDate > '$data' ";
$sql3= mysqli_query($conn,$sql3);
$res3=mysqli_fetch_all($sql3,MYSQLI_ASSOC);
$count = mysqli_num_rows($sql3);
$counter = 0;
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>过期提醒</title>
    <link rel="stylesheet" href="../css/expire.css">
    <link rel="stylesheet" href="../img/Public Section img">
    <link href="https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css" rel="stylesheet" />
    <!-- <script src="../js/Public Section.js"></script> -->
</head>

<body>

    <!--背景-->
    <div class="all">
    <!-- 左手边菜单栏 -->
        <div class="h left_Menu_Bar Center">
            <div class="Menu_Bar Center">
                <!-- 头像 -->
                <div class="avatar">
                    <!-- 默认头像 -->
                    <h1>读</h1>
                </div>
                <!-- 菜单 -->
                <div class="Menu Font">
                    <ul class="Center ct">
                        <li><a href="#">用户管理</a></li>
                        <li>
                            <a href="#">借阅管理</a> <button class="btn" id="btn"><i class="bx bx-chevron-down"
                                    id="arrow"></i></button>
                        </li>
                        <!-- 下拉菜单 -->
                        <div class="box " id="dropdown">
                            <ul class="drop_down_menu Center">
                                <li><a href="../html/borrow.html">借阅</a></li>
                                <li><a href="../html/return.html">归还</a></li>
                                <li><a href="#">记录</a></li>
                                <li><a href="expire.php">过期</a></li>
                            </ul>
                        </div>

                        <li><a href="../html/Book Information.html  ">图书列表</a></li>

                    </ul>
                </div>
            </div>
        </div>
        <!-- -------------右侧-------------------------- -->

        <!-- <div class="h bodyed"> -->
        <!-- 白色背景 -->
        <div class="Background">
            <!-- 标题 -->
            <h1 class="title">过期提醒</h1>
            <div class="sn">
                <span>即将过期</span>
            </div>
            <div class="ple_ret">
                <img src="../image/催付数据.png" alt="">
                <div class="nr">有<?echo $count?>本图书已过期，请尽快归还!</div>
            </div>

            <div class="top">
                <table>
                    <thead>
                            <tr>
                                <th><b>索书号</b></th>
                                <th><b>条形码</b></th>
                                <th><b>书籍</b></th>
                                <th><b>文献所在地</b></th>
                                <th><b>借阅时间</b></th>
                                <th><b>归还时间</b></th>  
                            </tr>
                    </thead>

                    <tbody>
                    <?foreach ($res3 as $value1){?>
                        <?php $counter++; ?>
                        <tr class="<?php echo ($counter % 2 == 0) ? 'even' : 'odd'; ?>">
                            <th><?echo $value1['RecordID']?></th>
                            <th><?echo $value1['BookID']?></th>
                            <th><?echo $value1['Bookname']?></th>
                            <th><?echo $value1['di']?></th>
                            <th><?echo $value1['BorrowDate']?></th>
                            <th><?echo $value1['ReturnDate']?></th>
                        </tr>
<?}?>
                    </tbody>
                </table>
                <div class="foot">
                    <div>更多</div>
                    <img src="../image/向下.png" alt="">
                </div>
            </div>
<!-- -------------------------------下半----------------------------------- -->
            <div class="bo-2">
                <div class="sn" >
                    <span>已过期</span>
                </div>
                <div class="ple_ret">
                    <img src="../image/催付数据.png" alt="">
                    <div class="nr">有<?echo $count1?>本图书已过期，请尽快归还!</div>
                </div>
                
                <div class="top"></div>
                    <table>
                        <thead>
                                <tr>
                                    <th><b>索书号</b></th>
                                    <th><b>条形码</b></th>
                                    <th><b>书籍</b></th>
                                    <th><b>文献所在地</b></th>
                                    <th><b>借阅时间</b></th>
                                    <th><b>归还时间</b></th>  
                                </tr>
                        </thead>
                        <tbody>
                        <?foreach ($res5 as $value2){?>
                            <?php $counter++; ?>
                            <tr class="<?php echo ($counter % 2 == 0) ? 'even' : 'odd'; ?>">
                                <th><?echo $value2['RecordID']?></th>
                                <th><?echo $value2['BookID']?></th>
                                <th><?echo $value2['Bookname']?></th>
                                <th><?echo $value2['di']?></th>
                                <th><?echo $value2['BorrowDate']?></th>
                                <th><?echo $value2['ReturnDate']?></th>
                            </tr>
<?}?>
                        </tbody>
                    </table>
                    <div class="foot">
                        <div>更多</div>
                        <img src="../image/向下.png" alt="">
                    </div>
                </div>
            </div>
        </div>


</body>

</html>

<script src="../js/expire.js"></script>